package com.amado.course29Enum;

/**
 * 枚举测试类 商品一级分类枚举类
 */
public enum GoodsCateTypeEnum {
	//public staic final String TRAIN="V001";
	//public staic final String TRAIN_VALUE="培训";
	TRAIN("V001", "培训"), MATCH("V002", "比赛");
	//TRAIN对应GoodsCateTypeEnum(String code, String name)，相当于调用了构造函数
	private String code;
	private String name;

	public String getCode() {
		return code;
	}

	public String getName() {
		return name;
	}
	//私用的构造函数
	private GoodsCateTypeEnum(String code, String name) {
		this.code = code;
		this.name = name;
	}

	public static String getName(String code) {
		GoodsCateTypeEnum[] values = GoodsCateTypeEnum.values();
		for(GoodsCateTypeEnum tempEnum:values){
			if(tempEnum.getCode().equals(code)){
				return tempEnum.getName();
			}
		}
		return null;
	}

	public static void main(String[] args) {
		String goodsCateCode = "V001";
		System.out.println(GoodsCateTypeEnum.getName(goodsCateCode));
		if(GoodsCateTypeEnum.TRAIN.getCode().equals(goodsCateCode)){
			System.out.println(GoodsCateTypeEnum.MATCH.getName());
		}else if(GoodsCateTypeEnum.MATCH.getCode().equals(goodsCateCode)){
			System.out.println(GoodsCateTypeEnum.MATCH.getName());
		}else{
			System.out.println("。。。。。。。。。");
		}
	}
}